<%-- 
    Document   : register
    Created on : Dec 10, 2013, 7:38:47 AM
    Author     : brlnt
--%>
<%@include file="../template/header.jsp" %>
<%
    UserBean userdata;
    boolean stsEdit = false;
    boolean editAdmin = false;
    boolean field = false;
    boolean register = false;
    boolean message = false;
    int role = 0;
    UserBean sesiUser = (UserBean) session.getAttribute("sesiUser");
    if (request.getAttribute("editadmin") != null) {
        userdata = (UserBean) request.getAttribute("editadmin");
        editAdmin = true;
        field = true;
        role = userdata.getRole();
    } else if(request.getAttribute("editprofil") != null) {
        userdata = (UserBean) request.getAttribute("editprofil");
        field = true;
        stsEdit = true;
   } else if (request.getAttribute("error") != null){
       userdata= (UserBean) request.getAttribute("error");
       field = true;
       message = true;
   } else{
        userdata = null;
   }
    
   if(request.getAttribute("tombol").equals("Daftar")){
        register = true;
   }
%>
<script src="${initParam.js}/parsley.js"></script>
<script src="${initParam.js}/parsley.extend.js"></script>
<div class="row">
    <div class="col-lg-6 col-lg-push-1">
        <form action=".${alamat}" method="POST" parsley-validate novalidate>
            <fieldset>
                <h3>${title}</h3>
                <hr>
                <label>Nama Depan</label>
                <input type="text" class="form-control" placeholder="Nama Depan" name="namaDepan" value="<% if (field) { %><%=userdata.getFirstName()%><%}%>" <% if (editAdmin) {%>readonly="readonly"<%}%> parsley-maxlength="50" parsley-required="true">
                <label>Nama Belakang</label>
                <input type="text" class="form-control" placeholder="Nama Belakang" name="namaBelakang" value="<% if (field) { %><%=userdata.getLastName()%><%}%>" <% if (editAdmin) {%>readonly="readonly"<%}%> parsley-maxlength="50" parsley-required="true">
                <label>Alamat Surel</label>
                <input type="email" class="form-control" placeholder="surel@contoh.co.id" name="email" value="<% if (field) { %><%=userdata.getEmail()%><%}%>" <% if (editAdmin) {%>readonly="readonly"<%}%> parsley-required="true" parsley-maxlength="254">
                <% if (message){ %>
                <ul class="parsley-error-list">
                    <li style="display: list-item;">
                        ${messageEmail}
                    </li>
                </ul>
                <% } %>
                <% if (!editAdmin) { %>
                    <% if (stsEdit) { %>
                <label>Kata Sandi Lama</label>
                <input type="password" class="form-control" name="password-lama" value="">
                    <% } %>
                <label>Kata Sandi <% if (stsEdit) { %>Baru<% } %></label>
                <input type="password" class="form-control" name="password" id="password" parsley-equalto="#konfirm-password" value=""  >
                <label>Konfirmasi Kata Sandi <% if (stsEdit) { %>Baru<% } %></label>
                <input type="password" class="form-control" name="konfirmasiPassword" id="konfirm-password" parsley-equalto="#password" value="" >
                <% } %>
                <%if (sesiUser != null) {%>
                    <% if(editAdmin || sesiUser.getRole() == 1){ %>
                <label>Role</label>
                <select name="role" class="form-control">
                    <option value="1" <% if (editAdmin && role == 1) { %>selected<% } %>>Admin</option>
                    <option value="2" <% if (editAdmin && role == 2) { %>selected<% } %>>Validator</option>
                    <option value="3" <% if (editAdmin && role == 3) { %>selected<% } %>>Kontributor</option>
                    <option value="4" <% if (editAdmin && role == 4) { %>selected<% }%>>Masyarakat</option>
                </select>
                <% 
                        }
                    } 
                %>
                <% if (register){ %>
                <input type="hidden" class="form-control" name="role" value="4">
                <% } %>
                <label></label>
                <% if (editAdmin){ %>
                <input type="hidden" class="form-control" name="id" value="<%=userdata.getIdUser()%>">
                <% } %>
                <button type="submit" class="btn btn-primary form-control">${tombol}</button>
            </fieldset>
        </form>
    </div>
</div>
<%@include file="../template/footer.jsp" %>